from rest_framework.generics import ListAPIView
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.viewsets import ModelViewSet

from apps.goods.models import SPU, Brand, GoodsCategory
from apps.meiduo_admin.serializers.spu import SPUModelSerializer, BrandModelSerializer, ChannelModelSerializer
from apps.meiduo_admin.utils import PageNum


class CateChannelAPIView(APIView):
    def get(self, request, pk):
        data = GoodsCategory.objects.filter(parent=pk)
        serializer = ChannelModelSerializer(data, many=True)
        return Response(serializer.data)

class ChannelAPIView(ListAPIView):
    queryset = GoodsCategory.objects.filter(parent=None)
    serializer_class = ChannelModelSerializer

class BrandAPIView(ListAPIView):
    queryset = Brand.objects.all()
    serializer_class = BrandModelSerializer


class SPUAPIView(ModelViewSet):
    queryset = SPU.objects.all()
    serializer_class = SPUModelSerializer
    pagination_class = PageNum